<template>
  <el-form ref="formRef" :model="numberValidateForm" label-width="auto" class="demo-ruleForm">
    <div class="task-points">
      <cproPublic title="任务分配积分（不可大于项目总积分）" :show-stat="true">
        <template v-slot:content>
          <el-form-item
            prop="points"
            class="item"
            :rules="[
              { required: true, message: '必须填写任务积分' },
              { type: 'number', message: '积分必须为数字' }
            ]"
          >
            <el-input
              class="input"
              v-model.number="numberValidateForm.points"
              type="number"
              placeholder="请输入当前任务包含的总积分"
            />
          </el-form-item>
        </template>
      </cproPublic>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import { ElMessage } from 'element-plus'
import cproPublic from '@/components/creat-projects/cpro-public.vue'
import {ref,reactive } from 'vue'
const  numberValidateForm  = reactive({points:''})
const emit = defineEmits(['updateScore'])

const formRef = ref<FormInstance>()
//父组件调用提交的方法
const upLoadPoints = ():Boolean=>{
  //积分填写不规范报错
 if(!numberValidateForm.points){
  ElMessage({
    showClose: true,
    message: '请填写项目总积分！！',
    type: 'error',
  })
  return false
 } else if(Number( numberValidateForm.points) <= 0){
  ElMessage({
    showClose: true,
    message: '积分必须大于0！！',
    type: 'error',
  })
  return false
 }else{
  emit('updateScore',numberValidateForm.points)
  return true
 }

}
defineExpose({upLoadPoints})
</script>

<style scoped>
.task-points {
  .item {
    margin: 0 0 0 8px;
  }
  .input {
    border: 1px solid #e4e4e4;
    border-radius: 5px;
    width: 1070px;
    height: 40px;
    line-height: 40px;
    font-size: 13px;
  }
}
</style>
